﻿using ChatWithMe.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Phone.UI.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;


// “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234238 上提供

namespace ChatWithMe.Views
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class LoginPage : Page
    {
        public LoginViewModel ViewModel { get; set; }
        public LoginPage()
        {
            ViewModel = new LoginViewModel();
            this.InitializeComponent();
            
        }


        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {

            //判断系统是否有该API
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
            {
                var statusbar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
                statusbar.ProgressIndicator.ProgressValue = 0;
                statusbar.ProgressIndicator.Text = " ";
                //在状态栏中展示进度条
                await statusbar.ProgressIndicator.ShowAsync();
            }



            //播放FaddIn动画
            fadeIn.Begin();

            //重写后退键
  //          HardwareButtons.BackPressed += HardwareButtons_BackPressed;

        }
        #region 退出逻辑
        //bool isExiting = false;
        //private async void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
        //{


        //    if(isExiting)
        //    {
        //        App.Current.Exit();
        //    }
        //    else
        //    {
        //        exitTipShow.Begin();
        //        isExiting = true;
        //        exitTipShow.Completed+=exitTipShow_Completed;

        //    }
        //    e.Handled = true;
        //    #region 异步实现
        //    ////短时间内（2秒）  点两次后退键
        //    //if(isExiting)
        //    //{
        //    //    //退出应用程序

        //    //    App.Current.Exit();
        //    //}
        //    //else
        //    //{
        //    //    //展示正在退出提示 并将isExiting设为true
        //    //    exitTips.Visibility = Visibility.Visible;
        //    //    isExiting = true;

        //    //    //显示两秒
        //    //    await Task.Delay(2000);
        //    //    exitTips.Visibility = Visibility.Collapsed;
        //    //    isExiting = false;
        //    //}
            #endregion


        //}

        //private void exitTipShow_Completed(object sender, object e)
        //{
        //    isExiting = false;
        //    exitTipShow.Completed -= exitTipShow_Completed;
        //}
    }
}
